/**
 * 	this is the Main Window Panel
 */

package gui;

import javax.swing.JPanel;
import javax.swing.JButton;

import common.ChatIF;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class MainWindow extends JPanel implements ChatIF{
	int privilege[];
	private String pid;
	private AcademicFrame frame;
	private AssessorPanel assessor;
	private InitiatorPanel initiator;
	private SupervisorPanel supervisor;
	private LoginPanel login;
	private ExecutionLeaderPanel executionLeader;
	private CommitteeMemberPanel committeeMember;
	private InformationDepartmentManagerPanel informationDManager;
	private ArrayList<Object> listofAssessorRequests;
	MainWindow mainWindow;
	
	
	public MainWindow(AcademicFrame frame, LoginPanel login, int privilege[],String pid) {
		super();
		this.pid=pid;
		this.frame=frame;
		this.privilege=privilege;
		this.login=login;
		this.initiator = new InitiatorPanel(frame,this,pid);
	//	this.assessor=new AssessorPanel(frame,this,pid);
		this.executionLeader=new ExecutionLeaderPanel(frame,this,pid);
		this.supervisor=new SupervisorPanel(frame,this,true,pid);
		this.mainWindow=this;
		frame.setSize(500, 500);
		initialize();
	}
	
	private void initialize() {
		setLayout(null);
		JButton btnInitiator = new JButton("Initiator");
		btnInitiator.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frame.setSize(500, 400);
				frame.setContentPane(initiator);
			}
		});
		btnInitiator.setBounds(10, 11, 193, 23);
		add(btnInitiator);
		
		JButton btnAssessor = new JButton("Assessor");
		btnAssessor.setEnabled(false);

		if(privilege[1]==1)
			btnAssessor.setEnabled(true);

		btnAssessor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				assessor=new AssessorPanel(frame,mainWindow,pid);
				frame.setSize(500, 400);
				frame.setContentPane(assessor);				
			}
		});
		btnAssessor.setBounds(10, 45, 193, 23);
		add(btnAssessor);
		
		JButton btnSupervisor = new JButton("Supervisor");
		btnSupervisor.setEnabled(false);
		if(privilege[0]==1)
			btnSupervisor.setEnabled(true);
		else
			this.supervisor=new SupervisorPanel(frame,this,true, pid);
		
		btnSupervisor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//supervisor=new SupervisorPanel(frame,mainWindow);
				frame.setSize(500, 400);
				frame.setContentPane(supervisor);
			}
		});
		btnSupervisor.setBounds(10, 79, 193, 23);
		add(btnSupervisor);
		
		JButton btnExecutionLeader = new JButton("Execution Leader");
		btnExecutionLeader.setEnabled(false);
		if(privilege[2]==1)
			btnExecutionLeader.setEnabled(true);
		else
			this.executionLeader=new ExecutionLeaderPanel(frame,this,pid);
		
		btnExecutionLeader.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setSize(500, 400);
				frame.setContentPane(executionLeader);
			}
		});
		btnExecutionLeader.setBounds(10, 113, 193, 23);
		add(btnExecutionLeader);
		
		JButton btnCommitteeMember = new JButton("Committee Member");
		btnCommitteeMember.setEnabled(false);
		if(privilege[3]==1)
		{
			btnCommitteeMember.setEnabled(true);
			if(privilege[4]==1) //is a chairman
				this.committeeMember=new CommitteeMemberPanel(frame,this,true, pid);
			else
				this.committeeMember=new CommitteeMemberPanel(frame,this,false, pid);
		}
		btnCommitteeMember.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setSize(500, 400);
				frame.setContentPane(committeeMember);
			
			}
		});
		btnCommitteeMember.setBounds(10, 147, 193, 23);
		add(btnCommitteeMember);
		
		
		JButton btnInformationDepartmentManager = new JButton("Information Department Manager");
		btnInformationDepartmentManager.setEnabled(false);
		if(privilege[5]==1)
		{
			btnInformationDepartmentManager.setEnabled(true);
			this.informationDManager=new InformationDepartmentManagerPanel(frame,this);
		}
		else
		{
			btnInformationDepartmentManager.setEnabled(false);			
		}
			
		
		btnInformationDepartmentManager.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setSize(500, 700);
				frame.setContentPane(informationDManager);
			}
		});
		btnInformationDepartmentManager.setBounds(10, 181, 193, 23);
		add(btnInformationDepartmentManager);
		
		JButton btnLogout = new JButton("Logout");
		btnLogout.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				frame.setSize(300, 300);
				frame.setContentPane(login);
				AcademicFrame.logOff();
			}
		});
		btnLogout.setBounds(10, 215, 193, 23);
		add(btnLogout);	
		
	}

	@Override
	public void display(Object message) {
		// TODO Auto-generated method stub
		
	}
}
